//
//  BIDFeedbackViewController.m
//  zhangqitong
//
//  Created by mal on 16/1/10.
//  Copyright © 2016年 mal. All rights reserved.
//

#import "BIDFeedbackViewController.h"
#import "BIDCustomTextView.h"

static NSString *feedbackURL = @"feedbackAndroid!addFeedback.action";

@interface BIDFeedbackViewController ()<UIActionSheetDelegate, UIAlertViewDelegate>
{
    //反馈类型
    int _type;
}
@end

@implementation BIDFeedbackViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"反馈";
    [self.view setBackgroundColor:RGBACOLOR(226, 233, 243, 1)];
    _typeTextView.placeholder = @"反馈类型...";
    _contentTextView.placeholder = @"反馈内容...";
    _contentTextView.inputAccessoryView = self.toolBar;
    // Do any additional setup after loading the view from its nib.
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"发送" style:UIBarButtonItemStylePlain target:self action:@selector(feedbackHandler)];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (void)feedbackHandler
{
    if(_typeTextView.text.length==0)
    {
        [BIDGlobalMethods showAlertView:@"请选择反馈类型" buttonTitle:ALERT_BTN_TITLE delegate:nil tag:0];
        return;
    }
    if(_contentTextView.text.length==0)
    {
        [BIDGlobalMethods showAlertView:@"请填写反馈内容" buttonTitle:ALERT_BTN_TITLE delegate:nil tag:0];
        return;
    }
    NSString *strRequestURL = [[NSString alloc] initWithFormat:@"%@/%@", [AppDelegate getServerAddr], feedbackURL];
    NSString *strPost = [[NSString alloc] initWithFormat:@"createId=%@&content=%@&type=%d", [AppDelegate getUserId], _contentTextView.text, _type];
    [self sendHttpRequestWithURL:strRequestURL postData:strPost withCompletion:^(NSDictionary *responseDic, NSString *errMsg){
        if(responseDic)
        {
            [BIDGlobalMethods showAlertView:@"反馈成功" buttonTitle:ALERT_BTN_TITLE delegate:self tag:1];
        }
    }];
}

- (IBAction)btnDownHandler:(id)sender
{
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"使用建议", @"使用故障", nil];
    [actionSheet showInView:[UIApplication sharedApplication].keyWindow];
}

#pragma mark - UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(alertView.tag == 1)
    {
        [self.navigationController popViewControllerAnimated:YES];
    }
}

#pragma mark - UIActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(buttonIndex==0)
    {
        _type = 1;
        _typeTextView.text = @"使用建议";
    }
    else if(buttonIndex==1)
    {
        _type = 2;
        _typeTextView.text = @"使用故障";
    }
}

@end
